home *** CD-ROM | disk | FTP | other *** search
-
-
- /*© Copyright 1988-1992 UserLand Software, Inc. All Rights Reserved.*/
-
-
- #include "iacinternal.h"
-
-
- typedef struct tysystemhandler {
-
- AEEventClass eventclass;
-
- AEEventID id;
-
- tyAEHandler proc;
-
- long A5;
-
- THz heapzone;
-
- struct tysystemhandler **hnexthandler;
- } tysystemhandler, **hdlsystemhandler;
-
-
- hdlsystemhandler hfirstsystemhandler = nil;
-
-
-
-
- static pascal OSErr callhandler (AppleEvent *event, AppleEvent *reply, long refcon) {
-
- hdlsystemhandler h = (hdlsystemhandler) refcon;
- long appA5;
- THz savedzone;
- OSErr ec;
-
- appA5 = (**h).A5;
-
- asm { /*save all registers, set value of A5*/
-
- movem.l a0-a6/d0-d7, -(sp)
-
- move.l appA5, a5
- }
-
- savedzone = GetZone ();
-
- SetZone ((**h).heapzone);
-
- ec = (*(**h).proc) (event, reply, 0L);
-
- SetZone (savedzone);
-
- asm { /*restore all registers*/
-
- movem.l (sp)+, a0-a6/d0-d7
- }
-
- return (ec);
- } /*callhandler*/
-
-
- Boolean IACinstallsystemhandler (AEEventClass eventclass, AEEventID id, ProcPtr handler) {
-
- OSErr ec;
- hdlsystemhandler h;
-
- h = (hdlsystemhandler) NewHandle ((long) sizeof (tysystemhandler));
-
- if (h == nil)
- return (false);
-
- (**h).eventclass = eventclass;
-
- (**h).id = id;
-
- (**h).proc = (tyAEHandler) handler;
-
- (**h).A5 = (long) CurrentA5;
-
- (**h).heapzone = GetZone ();
-
- ec = AEInstallEventHandler (eventclass, id, (EventHandlerProcPtr) callhandler, (long) h, true);
-
- IACglobals.errorcode = ec;
-
- if (ec != noErr) {
-
- DisposHandle ((Handle) h);
-
- return (false);
- }
-
- (**h).hnexthandler = hfirstsystemhandler;
-
- hfirstsystemhandler = h;
-
- return (true);
- } /*IACinstallsystemhandler*/
-
-
- Boolean IACremovesystemhandler (AEEventClass eventclass, AEEventID id, ProcPtr handler) {
-
- hdlsystemhandler h = hfirstsystemhandler;
- hdlsystemhandler hprev = nil;
- OSErr ec;
-
- while (h != nil) {
-
- if (((**h).eventclass == eventclass) && ((**h).id == id)) {
-
- ec = AERemoveEventHandler (eventclass, id, (EventHandlerProcPtr) callhandler, true);
-
- if (hprev == nil)
- hfirstsystemhandler = (**h).hnexthandler;
- else
- (**hprev).hnexthandler = (**h).hnexthandler;
-
- DisposHandle ((Handle) h);
-
- return (true);
- }
-
- hprev = h;
-
- h = (**h).hnexthandler;
- } /*while*/
-
- return (false);
- } /*IACremovesystemhandler*/
-
-
- void IACremovesystemhandlers (void) {
-
- /*
- remove all system event handlers that were installed by this application.
-
- 3/4/93 DW: make it possible for this routine to be called two or more times.
- */
-
- hdlsystemhandler h = hfirstsystemhandler;
- hdlsystemhandler hnext;
- OSErr ec;
-
- while (h != nil) {
-
- ec = AERemoveEventHandler ((**h).eventclass, (**h).id, (EventHandlerProcPtr) callhandler, true);
-
- IACglobals.errorcode = ec;
-
- hnext = (**h).hnexthandler;
-
- DisposHandle ((Handle) h);
-
- h = hnext;
- } /*while*/
-
- hfirstsystemhandler = nil; /*3/4/93*/
- } /*IACremovesystemhandlers*/
-
-
-